package cn.xz.zgsg.dialog

import android.view.Gravity
import android.widget.TextView
import cn.xz.zgsg.R
import cn.xz.zgsg.base.BaseDialogRxFragment

/**
 * 重新登录提示弹窗
 * */
class CLoginDialog: BaseDialogRxFragment() {

    private var mClickListener: OnClickListener? = null

    private var tvYes: TextView? = null
    private var tvNo: TextView? = null

    companion object {
        fun newInstance(
            clickListener: OnClickListener
        ): CLoginDialog {
            val dialog = CLoginDialog()
            dialog.mClickListener = clickListener
            return dialog
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_c_login
    }

    override fun configDialog() {
        this.setDialogSize(gravity = Gravity.CENTER,width = 300)
    }

    override fun initViews() {

        dialog?.let {
            tvYes = it.findViewById(R.id.tv_yes)
            tvNo = it.findViewById(R.id.tv_no)
        }

        //点击外部不隐藏
        dialog?.setCancelable(false)
        dialog?.setCanceledOnTouchOutside(false)
        //点击事件
        initEvent()
    }


    private fun initEvent(){
        tvYes?.setOnClickListener {
            mClickListener?.onYes()
            dismiss()
        }
        tvNo?.setOnClickListener {
            mClickListener?.onNo()
            dismiss()
        }
    }


    interface OnClickListener {
        fun onYes()
        fun onNo()
    }

}